package gui;

import java.sql.SQLException;

import gestionBDD.requetesContient;
import gestionBDD.requetesImage;
import interne.* ;
import com.trolltech.qt.gui.*;


public class fenetreUploadPhoto extends QWidget {
	
	Album album ;
	
    private QLineEdit titreimageLineEdit ;
    private QLineEdit commentaireLineEdit ;

    private QLineEdit cheminLineEdit ;
    private QLineEdit appareilphotoLineEdit ;
    private QLineEdit objectifLineEdit ;
    private QLineEdit distfocaleLineEdit ;
    private QLineEdit sensibiliteisoLineEdit ;
    private QLineEdit ouvertureLineEdit ;
    private QLineEdit vitesseobturationLineEdit ;
    private QLineEdit resolutionLineEdit ;

	public fenetreUploadPhoto(Album a) {
		
		setAlbum(a) ;
        
		/** Chemin's GroupBox' **/
        QGroupBox cheminGroup = new QGroupBox(tr("Image"));
        
        /* Chemin Line Edit with Label */
        QLabel cheminLabel = new QLabel(tr("Chemin :"));
        cheminLineEdit = new QLineEdit();
        cheminLineEdit.setFocus();

        /* Chemin Line Edit with Label */
        QLabel titreLabel = new QLabel(tr("Titre :"));
        titreimageLineEdit = new QLineEdit();
        titreimageLineEdit.setFocus();

        /* Chemin Line Edit with Label */
        QLabel commentaireLabel = new QLabel(tr("Commentaire :"));
        commentaireLineEdit = new QLineEdit();
        commentaireLineEdit.setFocus();
        
        /* Chemin's Layout */
        QGridLayout cheminLayout = new QGridLayout();
        cheminLayout.addWidget(cheminLabel, 0, 0);
        cheminLayout.addWidget(cheminLineEdit, 0, 1);
        cheminLayout.addWidget(titreLabel, 1, 0) ;
        cheminLayout.addWidget(titreimageLineEdit, 1, 1) ;
        cheminLayout.addWidget(commentaireLabel, 2, 0) ;
        cheminLayout.addWidget(commentaireLineEdit, 2, 1) ;
        
        cheminGroup.setLayout(cheminLayout);
        
        /** Détails' GroupBox' **/
        QGroupBox detailsGroup = new QGroupBox(tr("Détails"));	
        
        /* Chemin Line Edit with Label */
        QLabel appareilphotoLabel = new QLabel(tr("Appareil Photo :"));
        appareilphotoLineEdit = new QLineEdit();
        /* Chemin Line Edit with Label */
        QLabel objectifLabel = new QLabel(tr("Objectif :"));
        objectifLineEdit = new QLineEdit();
        /* Chemin Line Edit with Label */
        QLabel distfocaleLabel = new QLabel(tr("Distance focale :"));
        distfocaleLineEdit = new QLineEdit();
        /* Chemin Line Edit with Label */
        QLabel sensibiliteisoLabel = new QLabel(tr("Sensibilite ISO :"));
        sensibiliteisoLineEdit = new QLineEdit();
        /* Chemin Line Edit with Label */
        QLabel ouvertureLabel = new QLabel(tr("Ouverture :"));
        ouvertureLineEdit = new QLineEdit();
        /* Chemin Line Edit with Label */
        QLabel vitesseobturationLabel = new QLabel(tr("Vitesse obturation :"));
        vitesseobturationLineEdit = new QLineEdit();
        /* Chemin Line Edit with Label */
        QLabel resolutionLabel = new QLabel(tr("Résolution :"));
        resolutionLineEdit = new QLineEdit();
        
        /* Login's Layout */
        QGridLayout detailsLayout = new QGridLayout();
        detailsLayout.addWidget(appareilphotoLabel, 0, 0);
        detailsLayout.addWidget(appareilphotoLineEdit, 0, 1);
        detailsLayout.addWidget(objectifLabel, 1, 0);
        detailsLayout.addWidget(objectifLineEdit, 1, 1);
        detailsLayout.addWidget(distfocaleLabel, 2, 0);
        detailsLayout.addWidget(distfocaleLineEdit, 2, 1);
        detailsLayout.addWidget(sensibiliteisoLabel, 3, 0);
        detailsLayout.addWidget(sensibiliteisoLineEdit, 3, 1);
        detailsLayout.addWidget(ouvertureLabel, 4, 0);
        detailsLayout.addWidget(ouvertureLineEdit, 4, 1);
        detailsLayout.addWidget(vitesseobturationLabel, 5, 0);
        detailsLayout.addWidget(vitesseobturationLineEdit, 5, 1);
        detailsLayout.addWidget(resolutionLabel, 6, 0);
        detailsLayout.addWidget(resolutionLineEdit, 6, 1);
        detailsGroup.setLayout(detailsLayout);
        
        /* Ok Button Box */
        QDialogButtonBox boutonOk = new QDialogButtonBox();
        boutonOk.addButton(QDialogButtonBox.StandardButton.Ok);
        boutonOk.clicked.connect(this, "ajouterPhoto()");
        
        // Dialog Layout
        QGridLayout layout = new QGridLayout();
        layout.addWidget(cheminGroup, 0, 0);
        layout.addWidget(detailsGroup, 1, 0);
        layout.addWidget(boutonOk, 2, 1);
        setWindowTitle(tr("Nouvelle Photo"));
        setLayout(layout);
	}

	public Album getAlbum() {
		return album;
	}

	public void setAlbum(Album album) {
		this.album = album;
	}
	
	public void ajouterPhoto() throws SQLException {
		try {
			Image i = new Image(cheminLineEdit.text(), 
					appareilphotoLineEdit.text(), 
					resolutionLineEdit.text(),
					objectifLineEdit.text(), 
					distfocaleLineEdit.text(), 
					sensibiliteisoLineEdit.text(), 
					ouvertureLineEdit.text(), 
					vitesseobturationLineEdit.text());
			requetesImage.ajouterImage(i);
			requetesImage.trouverAvecChemin(i);
			Contient c = new Contient(album.getIdAlbum(), i.getIdImage(), 0, titreimageLineEdit.text(), commentaireLineEdit.text());
			requetesContient.ajouterContient(c);
			c = requetesContient.trouverId(c);
			requetesContient.corrigerOrdre(c);
			this.hide();
    	}
		catch(SQLException e) {
			System.out.println(e);
		}
	}
	
}
